package com.starry.home

import android.os.Build
import androidx.annotation.RequiresApi
import java.text.SimpleDateFormat
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.Calendar

/**
 * Package:com.starry.dotpen_patients
 * Author:starr
 * Time:2024/2/2 17:41
 * Description:
 */
@RequiresApi(Build.VERSION_CODES.O)
fun main(){
    print(dateWeek("2024-2-2"))

    // 获取今天的日期和星期
    val today = LocalDate.now()
    val dayOfWeekToday = today.dayOfWeek
    val dayOfWeekTextToday = dayOfWeekToday.toString()
    val formattedDateToday = today.format(DateTimeFormatter.ofPattern("MM-dd"))
    println("Today is $dayOfWeekTextToday, $formattedDateToday")

    for( i in 0..5){
        // 获取今天之后的五天日期和星期
        val fiveDaysFromToday = today.plusDays(i.toLong())
        val dayOfWeekFiveDaysFromToday = fiveDaysFromToday.dayOfWeek
        val dayOfWeekTextFiveDaysFromToday = dayOfWeekFiveDaysFromToday.toString()
        val formattedDateFiveDaysFromToday = fiveDaysFromToday.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))
        println("Five days from today is $dayOfWeekTextFiveDaysFromToday, $formattedDateFiveDaysFromToday")

    }

}

fun dateWeek(date: String): String {
    val calendar = Calendar.getInstance()
    val format = SimpleDateFormat("yyyy-MM-dd")
    calendar.time=format.parse(date)
    val dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK)
    val days = arrayListOf("周日", "周一", "周二", "周三", "周四", "周五", "周六")
    return "${days[dayOfWeek - 1]}\n"
}